home *** CD-ROM | disk | FTP | other *** search
/ Champak 103 / Vol 103.iso / interfac / it.dig / scripts / __Packages / mx / controls / listclasses / DataProvider.as next >
Text File  |  2010-03-13  |  5KB  |  149 lines

  1. class mx.controls.listclasses.DataProvider extends Object
  2. {
  3.    static var mixinProps = ["addView","addItem","addItemAt","removeAll","removeItemAt","replaceItemAt","getItemAt","getItemID","sortItemsBy","sortItems","updateViews","addItemsAt","removeItemsAt","getEditingData","editField"];
  4.    static var evtDipatcher = mx.events.EventDispatcher;
  5.    static var mixins = new mx.controls.listclasses.DataProvider();
  6.    function DataProvider(obj)
  7.    {
  8.       super();
  9.    }
  10.    static function Initialize(obj)
  11.    {
  12.       var _loc4_ = mx.controls.listclasses.DataProvider.mixinProps;
  13.       var _loc6_ = _loc4_.length;
  14.       obj = obj.prototype;
  15.       var _loc3_ = 0;
  16.       while(_loc3_ < _loc6_)
  17.       {
  18.          obj[_loc4_[_loc3_]] = mx.controls.listclasses.DataProvider.mixins[_loc4_[_loc3_]];
  19.          _global.ASSetPropFlags(obj,_loc4_[_loc3_],1);
  20.          _loc3_ = _loc3_ + 1;
  21.       }
  22.       mx.events.EventDispatcher.initialize(obj);
  23.       _global.ASSetPropFlags(obj,"addEventListener",1);
  24.       _global.ASSetPropFlags(obj,"removeEventListener",1);
  25.       _global.ASSetPropFlags(obj,"dispatchEvent",1);
  26.       _global.ASSetPropFlags(obj,"dispatchQueue",1);
  27.       Object.prototype.LargestID = 0;
  28.       Object.prototype.getID = function()
  29.       {
  30.          if(this.__ID__ == undefined)
  31.          {
  32.             this.__ID__ = Object.prototype.LargestID++;
  33.             _global.ASSetPropFlags(this,"__ID__",1);
  34.          }
  35.          return this.__ID__;
  36.       };
  37.       _global.ASSetPropFlags(Object.prototype,"LargestID",1);
  38.       _global.ASSetPropFlags(Object.prototype,"getID",1);
  39.       return true;
  40.    }
  41.    function addItemAt(index, value)
  42.    {
  43.       if(index < this.length)
  44.       {
  45.          this.splice(index,0,value);
  46.       }
  47.       else if(index > this.length)
  48.       {
  49.          trace("Cannot add an item past the end of the DataProvider");
  50.          return undefined;
  51.       }
  52.       this[index] = value;
  53.       this.updateViews("addItems",index,index);
  54.    }
  55.    function addItem(value)
  56.    {
  57.       this.addItemAt(this.length,value);
  58.    }
  59.    function addItemsAt(index, newItems)
  60.    {
  61.       index = Math.min(this.length,index);
  62.       newItems.unshift(index,0);
  63.       this.splice.apply(this,newItems);
  64.       newItems.splice(0,2);
  65.       this.updateViews("addItems",index,index + newItems.length - 1);
  66.    }
  67.    function removeItemsAt(index, len)
  68.    {
  69.       var _loc3_ = new Array();
  70.       var _loc2_ = 0;
  71.       while(_loc2_ < len)
  72.       {
  73.          _loc3_.push(this.getItemID(index + _loc2_));
  74.          _loc2_ = _loc2_ + 1;
  75.       }
  76.       var _loc6_ = this.splice(index,len);
  77.       this.dispatchEvent({type:"modelChanged",eventName:"removeItems",firstItem:index,lastItem:index + len - 1,removedItems:_loc6_,removedIDs:_loc3_});
  78.    }
  79.    function removeItemAt(index)
  80.    {
  81.       var _loc2_ = this[index];
  82.       this.removeItemsAt(index,1);
  83.       return _loc2_;
  84.    }
  85.    function removeAll(Void)
  86.    {
  87.       this.splice(0);
  88.       this.updateViews("removeItems",0,this.length - 1);
  89.    }
  90.    function replaceItemAt(index, itemObj)
  91.    {
  92.       if(index < 0 || index >= this.length)
  93.       {
  94.          return undefined;
  95.       }
  96.       var _loc3_ = this.getItemID(index);
  97.       this[index] = itemObj;
  98.       this[index].__ID__ = _loc3_;
  99.       this.updateViews("updateItems",index,index);
  100.    }
  101.    function getItemAt(index)
  102.    {
  103.       return this[index];
  104.    }
  105.    function getItemID(index)
  106.    {
  107.       var _loc2_ = this[index];
  108.       if(typeof _loc2_ != "object" && _loc2_ != undefined)
  109.       {
  110.          return index;
  111.       }
  112.       return _loc2_.getID();
  113.    }
  114.    function sortItemsBy(fieldName, order)
  115.    {
  116.       if(typeof order == "string")
  117.       {
  118.          this.sortOn(fieldName);
  119.          if(order.toUpperCase() == "DESC")
  120.          {
  121.             this.reverse();
  122.          }
  123.       }
  124.       else
  125.       {
  126.          this.sortOn(fieldName,order);
  127.       }
  128.       this.updateViews("sort");
  129.    }
  130.    function sortItems(compareFunc, optionFlags)
  131.    {
  132.       this.sort(compareFunc,optionFlags);
  133.       this.updateViews("sort");
  134.    }
  135.    function editField(index, fieldName, newData)
  136.    {
  137.       this[index][fieldName] = newData;
  138.       this.dispatchEvent({type:"modelChanged",eventName:"updateField",firstItem:index,lastItem:index,fieldName:fieldName});
  139.    }
  140.    function getEditingData(index, fieldName)
  141.    {
  142.       return this[index][fieldName];
  143.    }
  144.    function updateViews(event, first, last)
  145.    {
  146.       this.dispatchEvent({type:"modelChanged",eventName:event,firstItem:first,lastItem:last});
  147.    }
  148. }
  149.